package com.key.web_admin.controller;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.key.common.base.RespResult;
import com.key.modules.entity.Employee;
import com.key.modules.service.EmployeeService;
import com.key.modules.dto.EmployeeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/search")
    public RespResult<Page<Employee>> searchEmployeePage(){
        Page<Employee> page=new Page<>(1,10);
        Page<Employee> employeePage = employeeService.page(page);
        System.out.println("当前页码数："+employeePage.getCurrent());
        System.out.println("每页显示条数："+employeePage.getSize());
        System.out.println("总条数："+employeePage.getTotal());
        System.out.println("总页数："+employeePage.getPages());
        System.out.println("查询数据："+employeePage.getRecords());

        return RespResult.success(employeePage);
    }

    @GetMapping("/condition")
    public RespResult<Page<Employee>> searchEmployeePageByCondition(@RequestBody EmployeeDTO employeeDTO){
        Page<Employee> page=new Page<>(1,10);
        LambdaQueryWrapper<Employee> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.ge(employeeDTO.getBSalary()!=null,Employee::getSalary,employeeDTO.getBSalary())
                .le(employeeDTO.getESalary()!=null,Employee::getSalary,employeeDTO.getESalary())
                .ge(employeeDTO.getStart()!=null,Employee::getJoinDate,employeeDTO.getStart())
                .le(employeeDTO.getEnd()!=null,Employee::getJoinDate,employeeDTO.getEnd());
        Page<Employee> employeePage = employeeService.page(page,lambdaQueryWrapper);
        System.out.println("当前页码数："+employeePage.getCurrent());
        System.out.println("每页显示条数："+employeePage.getSize());
        System.out.println("总条数："+employeePage.getTotal());
        System.out.println("总页数："+employeePage.getPages());
        System.out.println("查询数据："+employeePage.getRecords());
       // StrUtil.isNotEmpty(employeeDTO.getBSalary())
        return RespResult.success(employeePage);
    }

}
